/*
 * test_threads.h
 *
 *  Created on: 17.12.2012
 *      Author: aska
 */

#ifndef TEST_THREADS_H_
#define TEST_THREADS_H_
#include <pthread.h>
#include <stdio.h>
#include <string>
#include <memory>
#include <iostream>
#include "door_control_dll_declarations.h"
//#include "main.h"
using namespace std;
class test_1_thread{
public:
	int rc;
	long t;
	pthread_t ping_thread_inst;
	pthread_t thread_inst;
	pthread_mutex_t mutex_command_test_1;
	//= PTHREAD_MUTEX_INITIALIZER;
	enum commands {no_command, quit};
	enum commands command;
	int test_is_running;
	//int test_2_is_running;
	int sleep_delay;
	int state_timer;
	int state_hopper;
	int state_door_control;
	int cycle_counter;
	int test_state;
	int test_period;
	int test_timer;
	int test_counter;
	//char ser_name[32];
	string ser_name;
	int ser_baud;
	door_control_lib * door_control_lib_inst;
	char log_file_name[255];	// Log file name
	char log_file_path[255];
	string log_file_name_string;
	string log_file_path_string;
	FILE * log_file_ptr;	// Log file pointer
	int log_file_year_day_prev;		// Log file previous day since January 1, for logging one file per day
	int log_file_year_day_pres;		// Log file current day since January 1
	int log_add_str(char * log_str);	// Function to write log string. Adds data in the beginning an and CR in the end of string.
	int log_add_timestamp(void);	// Function to write date and time to log
	test_1_thread(const test_1_thread& copy);         // copy constructor denied
	static void *thread_start(void *d)   { ((test_1_thread *)d)->run(); }
    int start()
    {
    	return pthread_create(
    			&ping_thread_inst,
    			0,
    			test_1_thread::thread_start,
    			(void*)this);
    }

	void run();

	test_1_thread();
	~test_1_thread();
	virtual void * test_proc(void *threadid);
	//void * test_2(void *threadid);
	//int thread_start(int inp_arg);
};

typedef std::auto_ptr<test_1_thread> t_test_1_thread_ptr;

#endif /* TEST_THREADS_H_ */
